/*
* 用户分析图
* */
import echart from 'echarts'
import numberFormat from '../utils/numberFormat'

const userTotal = (title, data, allCount, color) => {
  let option = {
    title: {
      text: title,
      textStyle: {
        color: '#50E3C2'
      },
      left: '6%',
      top: '3.5%'
    },
    tooltip: {
      trigger: 'item',
      formatter: '{a} <br/>{b} : {c} ({d}%)'
    },
    series: [
      {
        name: title,
        type: 'pie',
        radius: ['55%', '65%'],
        center: ['25%', '55%'],
        avoidLabelOverlap: false,
        label: {
          normal: {
            show: true,
            position: 'center',
            formatter: [
              `{a|${numberFormat(allCount)}}`,
              `{b|用户(名)}`
            ].join('\n'),
            rich: {
              a: {
                color: '#50E3C2',
                fontSize: 20
              },
              b: {
                color: '#fff',
                fontSize: 14,
                padding: [10, 0]
              }
            }
          }
        },
        labelLine: {
          normal: {
            show: false
          }
        },
        data: data
      }
    ],
    color: color
  }
  let user = echart.init(document.getElementById('userTotal'))
  user.setOption(option, true)
  window.addEventListener('resize', function () {
    user.resize()
  })
}

export default userTotal
